package com.test12;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

class TimeThread implements Callable<Long> {
    @Override
    public Long call() throws Exception {
        long start = System.currentTimeMillis();
        // 业务代码
        Thread.sleep(2300);
        long end = System.currentTimeMillis();
        return end - start;
    }
}

public class MyTest_03 {

    public static void main(String[] args) throws Exception {
        TimeThread body = new TimeThread();
        FutureTask<Long> futureTask = new FutureTask<>(body);
        new Thread(futureTask).start();
        System.out.println("运行结束，用时：" + futureTask.get() + " ms");
    }
}
